package isWinner;

public class Solution {
    public int isWinner(int[] player1, int[] player2) {
        int a = getNum(player1);
        int b = getNum(player2);
        if(a>b) return 1;
        if(a<b) return 2;
        return 0;
    }
    private int getNum(int[] player) {
        if(player.length == 1) {
            return player[0];
        }
        int ans = player[0] + player[0] == 10? player[1]*2:player[1];
        for (int i = 2; i < player.length; i++) {
            if(player[i-1] == 10|| player[i-2] == 10) {
                ans+=player[i]*2;
            }else {
                ans+=player[i];
            }
        }
        return ans;
    }
}
